/********************************************************************
	created:	2008/06/01
	created:	1:6:2008   15:54
	filename: 	x:\Lensow\Loplayer\src\app\CommandSink.cpp
	file path:	x:\Lensow\Loplayer\src\app
	file base:	CommandSink
	file ext:	cpp
	author:		Dean

	purpose:
*********************************************************************/
#include "StdAfx.h"
#include "LoPlayer.h"
#include "CommandSink.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

CCommandSink::SKIN_HANDLEMAP_ENTRY	CCommandSink::s_HandleEntries[] = {
	_T("Cmd_Minimize"),		WM_SYSCOMMAND,	SC_MINIMIZE,0,				NULL,
	_T("Cmd_Compact"),		0,0,0,				NULL,
	_T("Cmd_Maximize"),		0,0,0,				&OnMaximize,
	_T("Cmd_Close"),		WM_COMMAND,		ID_APP_EXIT,0,				NULL,
	_T("Cmd_Stop"),			WM_COMMAND,		ID_PLAY_STOP,0,				NULL,
	_T("Cmd_Previous"),		WM_COMMAND,		ID_NAVIGATE_BACK,0,			NULL,
	_T("Cmd_Next"),			WM_COMMAND,		ID_NAVIGATE_NEXT,0,			NULL,
	_T("Cmd_Play"),			WM_COMMAND,		ID_PLAY_PLAYPAUSE,0,		NULL,
	_T("Cmd_Open"),			WM_COMMAND,		ID_FILE_OPEN,0,	NULL,
	_T("Cmd_Mute"),			0,0,0,				&OnMute,
	_T("Cmd_ControlPanel"), 0,0,0,				&OnControlPanel,
	_T("Cmd_Playlist"),		0,0,0,				&OnPlaylist,
};


CCommandSink::CCommandSink(CWnd* pWndMsgSink)
: m_pWndMsgSink(pWndMsgSink)
{
}

CCommandSink::~CCommandSink(void)
{
}

LONG CCommandSink::HandleEvent( LPCTSTR lpszCmd, const CComVariant& vEvent )
{
	for (int i = 0; i < sizeof(s_HandleEntries) / sizeof(s_HandleEntries[0]); i++) {
		if (lstrcmpi (s_HandleEntries[i].szCommand, lpszCmd) == 0) {

			// post the command to main window
			if (s_HandleEntries[i].message){
				return GetSinkWnd()->PostMessage(s_HandleEntries[i].message, 
					s_HandleEntries[i].wParam, s_HandleEntries[i].lParam);
			}

			// call local function
			SKIN_PHANDLE pfn = s_HandleEntries[i].pfn;
			if (pfn != NULL) {
				return (this->*pfn) (vEvent);
			}

			//find out, but not handle it.
			break;
		}
	}

	return NOERROR;
}


//=============================================================================
LONG CCommandSink::OnMaximize( const CComVariant& )
{
	WINDOWPLACEMENT wp = {0};
	wp.length = sizeof(WINDOWPLACEMENT);

	GetSinkWnd()->GetWindowPlacement(&wp);
	if (SW_SHOWNORMAL == wp.showCmd){
		GetSinkWnd()->PostMessage(WM_SYSCOMMAND, SC_MAXIMIZE);
	}
	else{
		GetSinkWnd()->PostMessage(WM_SYSCOMMAND, SC_RESTORE);
	}

	return NOERROR;
}

//=============================================================================
LONG CCommandSink::OnStop( const CComVariant& )
{
	return NOERROR;
}

//=============================================================================
LONG CCommandSink::OnPrevious( const CComVariant& )
{
	return NOERROR;
}

LONG CCommandSink::OnNext( const CComVariant& )
{
	return NOERROR;
}

LONG CCommandSink::OnPlay( const CComVariant& )
{
	return NOERROR;
}

LONG CCommandSink::OnMute( const CComVariant& )
{
	return NOERROR;
}

LONG CCommandSink::OnControlPanel( const CComVariant& )
{
	return NOERROR;
}

LONG CCommandSink::OnPlaylist( const CComVariant& )
{
	return NOERROR;
}

